<?php

namespace app\admin\command;

use app\admin\command\Api\library\Builder;
use think\Config;
use think\console\Command;
use think\console\Input;
use think\console\input\Option;
use think\console\Output;
use think\Exception;
use think\Db;

class Tui extends Command
{
    protected function configure()
    {
        $this
            ->setName('tui')
            ->setDescription('自动退回');
    }

    protected function execute(Input $input, Output $output)
    {
        $one = Db::name('list_one')->whereIn('status',[1,2,3])->select();
        foreach($one as $k => $v){
            $data = array();
            $data['shen_time'] = time();
            $data['shen_peo'] = '系统操作';
            $data['shen_yijian'] = '超时退回修改';
            $data['did'] = $v['id'];
            $res = Db::name('yijian')->insert($data);
            //判断是否有已修改折折扣的
            $list_one_hf = Db::name('list_one_hf')->where(['one_id'=>$v['id']])->find();
            if($list_one_hf){
                $dataa = [
                    'main_sumdiscount'=>$list_one_hf['main_sumdiscount'],
                    'main_money' => $list_one_hf['main_money'],
                    'main_standard' => $list_one_hf['main_standard'],
                    'main_discount' => $list_one_hf['main_discount'],
                    'main_submit' => $list_one_hf['main_submit'],
                    'main_santong' => $list_one_hf['main_santong'],
                    'main_biao' => $list_one_hf['main_biao'],
                    'main_zhe' => $list_one_hf['main_zhe'],
                    'main_yingjiao' => $list_one_hf['main_yingjiao'],
                    'siji_tong' => $list_one_hf['siji_tong'],
                    'siji_biao' => $list_one_hf['siji_biao'],
                    'siji_zhe' => $list_one_hf['siji_zhe'],
                    'siji_ying' => $list_one_hf['siji_ying'],
                    'ck_money' => $list_one_hf['ck_money'],
                    'chengke_zuo' => $list_one_hf['chengke_zuo'],
                    'ck_tong' => $list_one_hf['ck_tong'],
                    'ck_biao' => $list_one_hf['ck_biao'],
                    'ck_zhe' => $list_one_hf['ck_zhe'],
                    'ck_ying' => $list_one_hf['ck_ying'],
                    'dao_tong' => $list_one_hf['dao_tong'],
                    'dao_biao' => $list_one_hf['dao_biao'],
                    'dao_zhe' => $list_one_hf['dao_zhe'],
                    'dao_ying' => $list_one_hf['dao_ying'],
                    'ziran_c' => $list_one_hf['ziran_c'],
                    'zi_tong' => $list_one_hf['zi_tong'],
                    'zi_biao' => $list_one_hf['zi_biao'],
                    'zi_zhe' => $list_one_hf['zi_zhe'],
                    'zi_ying' => $list_one_hf['zi_ying'],
                    'fd_c' => $list_one_hf['fd_c'],
                    'fdj_tong' => $list_one_hf['fdj_tong'],
                    'fdj_biao' => $list_one_hf['fdj_biao'],
                    'fdj_zhe' => $list_one_hf['fdj_zhe'],
                    'fdj_ying' => $list_one_hf['fdj_ying'],
                    'zd_tong' => $list_one_hf['zd_tong'],
                    'zd_biao' => $list_one_hf['zd_biao'],
                    'zd_zhe' => $list_one_hf['zd_zhe'],
                    'zd_ying' => $list_one_hf['zd_ying'],
                    'huowu_c' => $list_one_hf['huowu_c'],
                    'hw_tong' => $list_one_hf['hw_tong'],
                    'hw_biao' => $list_one_hf['hw_biao'],
                    'hw_zhe' => $list_one_hf['hw_zhe'],
                    'hw_ying' => $list_one_hf['hw_ying'],
                    'boli_c' => $list_one_hf['boli_c'],
                    'bl_tong' => $list_one_hf['bl_tong'],
                    'bl_biao' => $list_one_hf['bl_biao'],
                    'bl_zhe' => $list_one_hf['bl_zhe'],
                    'bl_ying' => $list_one_hf['bl_ying'],
                    'bu_tong' => $list_one_hf['bu_tong'],
                    'bu_biao' => $list_one_hf['bu_biao'],
                    'bu_zhe' => $list_one_hf['bu_zhe'],
                    'bu_ying' => $list_one_hf['bu_ying'],
                    'main_sum' => $list_one_hf['main_sum'],
                    'main_free' => $list_one_hf['main_free'],
                    'dw_tong' => $list_one_hf['dw_tong'],
                    'dw_biao' => $list_one_hf['dw_biao'],
                    'dw_zhe' => $list_one_hf['dw_zhe'],
                    'dw_ying' => $list_one_hf['dw_ying'],
                ];
            }
            //修改整体状态
            $dataa['status'] = 4;
            $ress = Db::name('list_one')->where('id',$v['id'])->update($dataa);
        }
        echo "成功退回".count($one)."个待支付";
        $output->info("Build Successed!");
    }


}
